using System;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.UI;

namespace SOFTECH
{
    public enum ModulePages
    {
        Product,
        Register,
        Download,
        RegisterList
    }

    public partial class Main : PortalModuleControl
    {
        //-----------------------------------------------------------------------------------------
        private void loadChildControl()
        {
            const string basePath = "~/Modules/SOFTECH/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page;
            if (pageName == null)
            {
                page = ModulePages.Product;
            }
            else
            {
                page = (ModulePages) Enum.Parse(typeof (ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            var ctl = (ModulePage) LoadControl(src);
            ctl.ParentControl = this;
            Controls.Add(ctl);
        }

        //-----------------------------------------------------------------------------------------
        protected void Page_Load(object sender, EventArgs e)
        {
            loadChildControl();
            if (IsPostBack == false)
            {
                hlRegisterList.Visible = PortalSecurity.HasManagerAuthorization(ModuleID);
                hlRegisterList.NavigateUrl = HttpUrlBuilder.BuildUrl(ModuleID, 0, ModulePages.RegisterList);
            }
        }
    }
}